var primePools = [];
var primes = [];

function getPrimes(limit) {
    var sqrt = Math.floor(Math.sqrt(limit));
    primePools[2] = 0;
    for(var i=2; i<=sqrt; i++) {
        for(var j=i*2; j<=limit; j=j+i) {
            primePools[j] = 1;
        }
    }
}

function isPrime(num) {
    return primePools[num] != 1
}

print('get primes.....');
var t=new Date().getTime();
var plimit = 1000000
getPrimes(plimit);
for(var i=2; i<=plimit; i++) {
    if(isPrime(i)) primes.push(i);
}
print('get primes done..... ' + ((new Date().getTime()-t)/1000) + "s");

var getFactorCount = function(num) {
    if(isPrime(num)) return 1;
    var count=0;
    for(var i=0; i<primes.length; i++) {
        if(num%primes[i]==0) {
            count++;
        }
        while(num%primes[i]==0) {
            num = num/primes[i];
        }
        if(num<=primes[i]) {
            return count;
        }
        if(num==1) {
            return count;
        }
    }
    return count;
}

var count4=0, startNumber=0;
for(var i=1; i<plimit; i++) {
    var tmp = getFactorCount(i);
    if(tmp==4) {
        if(count4==0) {
            startNumber=i;
        }
        count4 = count4 + 1;
        if(count4>2) {
            print(i + ".." + tmp + ".." + count4);
        }
        if(count4==4) {
            print("Find...." + startNumber);
            break;
        }
    } else {
        count4=0;
        //print(i + ".." + tmp + ".." + count4);
    }
}
